
interface item {
  hero: Info
  skins: detail[]
  spells: string
}
interface detail {
  centerImg: string
}
interface Info {
  shortBio: string
}
Page({
  data: {
    heroDetailItem: [] as string[],
    shortBio: '',
    activeIndex: 0
  },
  async onLoad(option) {
    wx.showLoading({
      title: '数据加载中'
    })
    console.log(option)
    const id = option.id
    const name = option.name
    await this.getData(id!)
    wx.setNavigationBarTitle({
      title: name || ''
    })
    //console.log(res)
    wx.hideLoading()
  },
  swiperChange(event: WechatMiniprogram.SwiperChange) {
    this.setData({
      activeIndex: event.detail.current
    })
  },
  getData(id: string) {
    return new Promise((resolve, reject) => {
      wx.request<heroResponse<item>>({
        url: 'https://api-vue-base.itheima.net/api/lol/info',
        method: 'GET',
        data: {
          id: id
        },
        success: (res) => {
          console.log(res)
          this.setData({
            heroDetailItem: res.data.data.skins.filter(item => item.centerImg !== '').map(item => item.centerImg),
            shortBio: res.data.data.hero.shortBio
          })
          resolve('')
        },
        fail: () => {
          reject('')
        }
      })
    })

  },
})